package com.lg.houtai.ui;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;

public class MainActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		if (NetUtil.checkNet(LogoActivity.this)) {
			// 开启服务
			if (!MainService.serviceState) {
				Intent intent = new Intent(LogoActivity.this, MainService.class);
				LogoActivity.this.startService(intent);
			}
			// 开启微博
			Weibo weibo = Weibo.getInstance();
			weibo.setupConsumerConfig(AppCode.CONSUMER_KEY, AppCode.CONSUMER_SECRET);
			weibo.setRedirectUrl(AppCode.REDIRECT_URL);

			SharedPreferences sp = LogoActivity.this.getSharedPreferences(SharedPreferencesConfig.SP_NAME, SharedPreferencesConfig.MODE_WR);
			String accessToken = sp.getString(Strings.ACCESS_TOKEN, "");
			long expiresIn = sp.getLong(Strings.EXPIRES_TIME, 0);

			Intent intent = null;

			// 自动登录
			if (StringUtils.isNotBlank(accessToken) && expiresIn != 0 && (expiresIn > System.currentTimeMillis())) {
				weibo.setAccessToken(new AccessToken(accessToken, AppCode.CONSUMER_SECRET));
				intent = new Intent(LogoActivity.this, MainActivity.class);
			} else {
				// 非自动登录
				intent = new Intent(LogoActivity.this, StartActivity.class);
			}
			startActivity(intent);
			finish();
		} else {
			MainService.alertNetError(LogoActivity.this);
		}
	}
}